<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <style>
            div{
            	width:400px;
            	height:150px;
            	border:1px dashed red;
            	margin:10px 0;
            }
        </style>
    </head>
    <script src="src/Itcast.core.js"></script>
    <script src="src/Itcast.dom.js"></script>
    <script>

        //简单优化
        /*Itcast.fn.appendTo=function(arr){
        	//this，是伪数组，要加的是this[0]
        	//将其加到arr[i]中
        	var tmp=[],tmpNode;
        	for(var j=0;j<this.length;j++){
                 for(var i=0;i<arr.length;i++){
                 	tmpNode=i==arr.length-1?this[j]:this[j].cloneNode(true);
                 	tmp.push(tmpNode);
                 	arr[i].appendChild(tmpNode);
                 }
        	}
        	return tmp;//最终要返回的是Itcast对象
        }*/

        Itcast.fn.appendTo=function(arr){
            //this,是伪数组，要加的是this[0]
            //将其加到arr[i]中
            var tmp=[],tmpNode;
            for(var j=0;j<this.length;j++){
                for(var i=0;i<arr.length;i++){
                    tmpNode=i==arr.length-1?this[j]:this[j].cloneNode(true);
                    tmp.push(tmpNode);
                    arr[i].apendChild(tmpNode);
                }
            }
            return tmp;//最终要返回的是Itcast对象
        }
    </script>
    <body>
        <div></div>
        <div></div>
        <div></div>
    </body>
    <script>
         var p1 = I( '<p>ppp</p><p>ppp</p><p>ppp</p><p>ppp</p>' );
        //var p1=I('<p>ppppp</p>');
        var p2=p1.appendTo(I('div'));
    </script>
</html>